Buttons to make users admins in the admin_panel

jamesperet 9 years ago
parent
commit
ff62f7310b

+ 21 - 1
app/controllers/admin_panel_controller.rb

@@ -24,7 +24,7 @@ class AdminPanelController < ApplicationController
24 24
   end
25 25
 
26 26
   def users
27
-    @users = User.all
27
+    @users = User.order('created_at DESC').all
28 28
   end
29 29
   
30 30
   def files
@@ -48,6 +48,26 @@ class AdminPanelController < ApplicationController
48 48
     end
49 49
   end
50 50
   
51
+  def make_admin
52
+    @user = User.find(params[:id])
53
+    if @user.admin == true
54
+      @user.admin = false
55
+      status = "admin_panel.unmake_admin_success"
56
+    else
57
+      @user.admin = true
58
+      status = "admin_panel.make_admin_success"
59
+    end
60
+    respond_to do |format|
61
+      if @user.save
62
+        format.html { redirect_to admin_users_path, notice: (t status) }
63
+        format.json { head :no_content }
64
+      else
65
+        format.html { redirect_to admin_users_path, alert: (t 'admin_panel.make_admin_error') }
66
+        format.json { head :no_content }
67
+      end
68
+    end
69
+  end
70
+  
51 71
   private
52 72
 
53 73
     # Never trust parameters from the scary internet, only allow the white list through.

+ 7 - 0
app/views/admin_panel/users.html.erb

@@ -34,6 +34,13 @@
34 34
 					  <span>Admin</span></span>
35 35
 				  </div>
36 36
 			  <% end %>
37
+			  <div class="pull-right">
38
+				<% if !user.admin %>
39
+				  	<%= link_to (t 'admin_panel.make_admin'), make_admin_path(user.id), class: 'btn btn-mini', style: 'width: 100px; margin-top: 6px; line-height: 17px;' %>
40
+				<% else %>
41
+					<%= link_to (t 'admin_panel.unmake_admin'), make_admin_path(user.id), class: 'btn btn-mini btn-danger', style: 'width: 100px; margin-top: 6px; line-height: 17px;' %>
42
+				<% end %>
43
+			  </div>
37 44
 			</div>
38 45
 		<% end %>
39 46
 	</div>

+ 5 - 0
config/locales/en.yml

@@ -228,6 +228,11 @@ en:
228 228
     maintenance_message: Maintenance Page Message
229 229
     on_switch: Disable
230 230
     off_switch: Enable
231
+    make_admin: Grant admin access
232
+    unmake_admin: Take away admin access
233
+    make_admin_success: The user was grated admin access.
234
+    unmake_admin_success: The user lost his admin access.
235
+    make_admin_error: User permission was not altered.
231 236
   nav:
232 237
     admin_panel: Admin Panel
233 238
     account: Account

+ 5 - 0
config/locales/pt-BR.yml

@@ -230,6 +230,11 @@ pt-BR:
230 230
     maintenance_message: Mensagem de manutenção
231 231
     on_switch: Ligado
232 232
     off_switch: Desligado
233
+    make_admin: Conceder acesso de administrador
234
+    unmake_admin: Tirar acesso de administrador
235
+    make_admin_success: O usuário agora tem acesso de administrador.
236
+    unmake_admin_success: O usuário não tem mais acesso de administrador.
237
+    make_admin_error: A permissão não foi alterada.
233 238
   nav:
234 239
     admin_panel: Painel de Controle
235 240
     account: Conta

+ 1 - 0
config/routes.rb

@@ -13,6 +13,7 @@ RailsWebsiteTemplate::Application.routes.draw do
13 13
   get "contact_message/:id/mark_contact_message_as_readed" => "contact_messages#readed", :as => :mark_contact_message_as_readed
14 14
   get "contact_message/:id/mark_contact_message_as_unread" => "contact_messages#unread", :as => :mark_contact_message_as_unread
15 15
   get "admin/users" => "admin_panel#users", :as => :admin_users
16
+  get "admin/users/:id/make_admin" => "admin_panel#make_admin", :as => :make_admin
16 17
   get "admin/config" => "admin_panel#site_config", :as => :admin_config
17 18
   post "admin/config/update" => "admin_panel#site_config_update", :as => :config_update
18 19
   

+ 0 - 1
readme.md

@@ -28,7 +28,6 @@ Other features are still under development:
28 28
 ## Todo's
29 29
 
30 30
 * edit account layout
31
-* make admin button
32 31
 
33 32
 * Install instructions
34 33
 * Heroku Deploy button